<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="${packageMapper}.${table.nameClass}Mapper">
	
	<!--主表表名 -->
	<sql id="tableName">
		${table.nameTable}
	</sql>
	
	<!-- 常规查询字段 -->
	<sql id="fieldh">
<#list table.listColumn as column>
	<#if column_has_next>
		${column.nameCol?uncap_first},
	<#else>
		${column.nameCol?uncap_first}
	</#if>
</#list>
	</sql>
	
	<!-- 插入字段 -->
	<sql id="fieldInsert">
<#list table.listColumn as column>
	<#if column_has_next>
		${column.nameCol?uncap_first},
	<#else>
		${column.nameCol?uncap_first}
	</#if>
</#list>
	</sql>
	
	<!-- 插入字段值 -->
	<sql id="fieldValue">
<#list table.listColumn as column>
	<#if column_has_next>
		${r'#{'}${column.nameCol?uncap_first}${r'}'},
	<#else>
		${r'#{'}${column.nameCol?uncap_first}${r'}'}
	</#if>
</#list>
	</sql>

	<!-- 新增实体 -->
	<insert id="insert" parameterType="${packageEntity}.${table.nameClass}">
        insert into 
        <include refid="tableName"></include> (
        <include refid="fieldInsert"></include>
        ) values (
        <include refid="fieldValue"></include>
        )
    </insert>
    
    <!-- 通过guid修改实体 -->
    <update id="update" parameterType="${packageEntity}.${table.nameClass}">
    	UPDATE 
    	<include refid="tableName"></include>
		SET
			<trim suffixOverrides=",">
<#list table.listColumn as column>
			<if test="${column.nameCol?uncap_first} != null">${column.nameCol} = ${r'#{'}${column.nameCol?uncap_first}${r'}'},</if>
</#list>
			</trim>
    	WHERE Guid = ${r'#{'}guid${r'}'} and Guid is not null
    </update>

	<delete id="deleteTrue">
		delete from <include refid="tableName"></include>
		where Guid = ${r'#{'}guid${r'}'}
	</delete>
</mapper>